/*
 * JsonrpcInterface.h
 *
 *  Created on: Apr 21, 2017
 *      Author: zhangjf
 */

#ifndef SRC_NETWORKSUBSYSTEM_JSONRPCINTERFACE_JSONRPCINTERFACE_H_
#define SRC_NETWORKSUBSYSTEM_JSONRPCINTERFACE_JSONRPCINTERFACE_H_

#include <map>
#include <string>
#include <functional>
#include <Poco/Logger.h>
#include <Poco/AutoPtr.h>
#include <Poco/JSON/Object.h>
#include <Poco/Dynamic/Var.h>
#include <Poco/RefCountedObject.h>

using namespace Poco;
using namespace Poco::JSON;
using namespace Poco::Dynamic;

namespace network
{

class JsonrpcInterface : public RefCountedObject
{
public:
	typedef AutoPtr<JsonrpcInterface> Ptr;

	JsonrpcInterface(const std::string& strMethod, Object::Ptr& joParams);
	virtual ~JsonrpcInterface();

	virtual bool process() = 0;

	virtual Object& getResult() { return _joResult; }
	virtual Object& getError() { return _joError; }

protected:
	std::string _strMethod;
	Object::Ptr& _joParams;
	Object _joResult;
	Object _joError;
};

class JsonrpcInterfaceFactory
{
public:
	static JsonrpcInterface::Ptr createInterface(std::string& interfacee, Object::Ptr& joParams);

private:
	static std::map<std::string, std::function<JsonrpcInterface::Ptr(Object::Ptr&)>> mapJRI;
	static void initialize();
};

} /* namespace network */

#endif /* SRC_NETWORKSUBSYSTEM_JSONRPCINTERFACE_JSONRPCINTERFACE_H_ */
